package com.web.base.wechat.util;

import java.util.ArrayList;
import java.util.List;

import com.blue.jdbc.Page;
import com.web.base.wechat.message.WechatTemplateRequest;
import com.web.base.wechat.message.WechatTemplateResponse;
import com.web.base.wechat.model.WechatTemplate;

public class WechatTemplateConvertor
{
	private WechatTemplateConvertor()
	{
	}
	
	public static WechatTemplate toWechatTemplate(WechatTemplateRequest request)
	{
		if (request == null)
			return null;
		
		WechatTemplate template = new WechatTemplate();
		template.setId(request.getId());
		template.setWechatId(request.getWechatId());
		template.setCode(request.getCode());
		template.setTplId(request.getTplId());
		template.setName(request.getName());
		template.setContent(request.getContent());
		template.setState(request.getState());
		return template;
	}
	
	public static WechatTemplateResponse toResponse(WechatTemplate template)
	{
		if (template == null)
			return null;
		
		WechatTemplateResponse response = new WechatTemplateResponse();
		response.setId(template.getId());
		response.setWechatId(template.getWechatId());
		response.setCode(template.getCode());
		response.setTplId(template.getTplId());
		response.setName(template.getName());
		response.setContent(template.getContent());
		response.setState(template.getState());
		
		response.setWechatName(template.getWechatName());
		return response;
	}
	
	public static List<WechatTemplateResponse> toResponse(List<WechatTemplate> list)
	{
		List<WechatTemplateResponse> responseList = new ArrayList<>();
		if (list == null || list.isEmpty())
			return responseList;
		
		for (WechatTemplate template : list)
		{
			responseList.add(toResponse(template));
		}
		return responseList;
	}
	
	public static Page<WechatTemplateResponse> toResponse(Page<WechatTemplate> page)
	{
		if (page == null)
			return null;
		
		Page<WechatTemplateResponse> responsePage = new Page<>();
		responsePage.setCurPage(page.getCurPage());
		responsePage.setRows(page.getRows());
		responsePage.setSize(page.getSize());
		responsePage.setStartRowNo(page.getStartRowNo());
		responsePage.setTotalPage(page.getTotalPage());
		responsePage.setObjectList(toResponse(page.getObjectList()));
		return responsePage;
	}
	
}
